//
//  BTEHomeViewController.swift
//  BTE
//
//  Created by Mike Zhang on 2025/8/5.
//

import UIKit

class BTEOrderViewController: BTEBaseViewController {
    
    var v: BTEOrderView {
        return view as! BTEOrderView
    }
    
    let listViewControllers = [
        BTEOrderSubViewController.init(OrderT: .actor),
        BTEOrderSubViewController.init(OrderT: .borrowing),
        BTEOrderSubViewController.init(OrderT: .consuming),
        BTEOrderSubViewController.init(OrderT: .packages)
    ]
    
    override func loadView() {
        view = BTEOrderView()
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        updateNavigationTitle(BTELanguageManager.shared.localizedString(forKey: "Order Center"))
        
        v.navScrollView.snp.remakeConstraints { make in
            make.top.equalTo(navigationBar.snp.bottom).offset(10)
            make.left.right.equalToSuperview().inset(18)
            make.height.equalTo(40)
        }
        
        listViewControllers.enumerated().forEach { item in
            addChild(item.element)
            v.listStackView.addSubview(item.element.view)
            item.element.view.snp.makeConstraints { make in
                make.height.equalToSuperview()
                make.width.equalTo(UIScreen.main.bounds.width)
                make.top.bottom.equalToSuperview()
                make.left.equalToSuperview().offset(CGFloat(item.offset)*UIScreen.main.bounds.width)
            }
            
            
            item.element.clickItem = {[weak self] idx in
                BTEUrlToolsManager.shared.handleURL(idx, in: self, model: nil)
            }
            
            // xieyi
            item.element.clickPro = {[weak self] idx in
                BTEUrlToolsManager.shared.handleURL(idx, in: self, model: nil)
            }
            
        }
        
        v.currenIdm = {[weak self] idx in
            self?.listViewControllers[idx].loadInfoaction()
        }
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        listViewControllers[v.displayIDX].loadInfoaction()
    }

}
